package com.htg.dialog;

import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast;


import java.util.ArrayList;
import java.util.List;


public class DialogPandu {

    private Context cxt;

    public DialogPandu(Context cxt) {
        this.cxt = cxt;
    }

    @SuppressLint("MissingInflatedId")
    public void show(View.OnClickListener onCancel, OnPanduSaveClickListener onPanduSaveClickListener) {
        AlertDialog.Builder builder = new AlertDialog.Builder(cxt);
        AlertDialog alertDialog = builder.create();
        alertDialog.setCanceledOnTouchOutside(true);

        View view = LayoutInflater.from(cxt).inflate(R.layout.dialog_pandu, null);
        Button btCancel, btSave;
        btCancel = view.findViewById(R.id.bt_dialog_pandu_cancel);
        btSave = view.findViewById(R.id.bt_dialog_pandu_save);
        CheckBox cbYzb, cbWzb, cbWdthj, cbCzdmpz, cbYtd, cbYjzw, cbJzwyjc,cbYwq, cbQt;
        EditText etQita;
        cbYzb = view.findViewById(R.id.cb_dialog_pandu_yzb);
        cbWzb = view.findViewById(R.id.cb_dialog_pandu_wzb);
        cbWdthj = view.findViewById(R.id.cb_dialog_pandu_wdthj);
        cbCzdmpz = view.findViewById(R.id.cb_dialog_pandu_czdmpz);
        cbYtd = view.findViewById(R.id.cb_dialog_pandu_ytd);
        cbYjzw = view.findViewById(R.id.cb_dialog_pandu_yjzw);
        cbJzwyjc = view.findViewById(R.id.cb_dialog_pandu_jzwyjc);
        cbYwq = view.findViewById(R.id.cb_dialog_pandu_ywq);
        cbQt = view.findViewById(R.id.cb_dialog_pandu_qt);
        etQita = view.findViewById(R.id.et_dialog_pandu_qita);

        btCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                alertDialog.dismiss();
                onCancel.onClick(v);
            }
        });
        btSave.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                List<String> items = new ArrayList<>();
                if (cbYzb.isChecked())
                    items.add("有植被");
                if (cbWzb.isChecked())
                    items.add("无植被");
                if (cbWdthj.isChecked())
                    items.add("无动土痕迹");
                if (cbCzdmpz.isChecked())
                    items.add("存在地面平整");
                if (cbYtd.isChecked())
                    items.add("有塔吊");
                if (cbYjzw.isChecked())
                    items.add("有建筑物");
                if (cbJzwyjc.isChecked())
                    items.add("建筑物已建成");
                if (cbYwq.isChecked())
                    items.add("有围墙");
                if (cbQt.isChecked())
                    items.add(etQita.getText().toString());
                if (items.size()<1){
                    Toast.makeText(cxt,"请选择",Toast.LENGTH_SHORT).show();
                    return;
                }
                alertDialog.dismiss();
                onPanduSaveClickListener.onPanduSaveClick(items);
            }
        });


        alertDialog.setView(view);
        alertDialog.show();

    }


    public interface OnPanduSaveClickListener {
        void onPanduSaveClick(List<String> items);
    }


}
